package com.gimi.test_jpa.com.gimi.service.wqy;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import com.gimi.test_jpa.com.gimi.dto.BaseDto;
import com.gimi.test_jpa.com.gimi.service.customer.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

@Service
@Transactional(rollbackFor = Exception.class)
public class TestService {
    @Autowired
    private CustomerService customerService;

    /**
     * 事务回滚测试
     *
     * @param cusId
     * @return
     */
    public String transactionTest(String cusId) {
        Boolean aBoolean = customerService.deleteCus(cusId);
        System.out.println(aBoolean);
//        return aBoolean+"";
        throw new RuntimeException("事务测试");
    }

    /**
     * aop测试
     *
     * @param str
     * @return
     */
    public String aspectTest(String str) {
        System.out.println("service方法执行,-----" + str);
        return str;
    }

    /**
     * aop测试2
     *
     * @param baseDto
     * @return
     */
    public String aspectTest2(BaseDto baseDto) {
        System.out.println("service方法执行,-----" + baseDto);
        return JSONUtil.toJsonStr(baseDto);
    }

    /**
     * aop测试3
     *
     * @param baseDto
     * @param code
     * @return
     */
    public String aspectTest3(BaseDto baseDto, String code) {
        Map<String, Object> map = BeanUtil.beanToMap(baseDto, false, true);
        map.put("code", code);
        return JSONUtil.toJsonStr(map);
    }
}
